#include<iostream>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
int a, b;
int main()
{
	int t;
	cin >> t;
	while (t--) {
		cin >> a >> b;
		if (a == 1 && b == 1) {
			cout << 2 << endl;
			continue;
		}
		else if (a == 1 || b == 1) {
			cout << a + b << endl;
		}
		else cout << 1 << endl;
	}
	return 0;
}